package top.malaoshi.controller;

import com.fasterxml.jackson.annotation.JsonInclude;
import org.springframework.web.bind.annotation.*;
import top.malaoshi.entity.Book;
import top.malaoshi.model.JsonResult;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/api")
public class BookCtrl {
    /*@RequestMapping("/{id}")
    public String get(@PathVariable String id){
        System.out.println("id:"+id);
        return "id:"+id;
    }*/
@GetMapping("/book/{id}")
public JsonResult get(@PathVariable String id){
    System.out.println("id:"+id);
    Book book=new Book(id,"母猪的产后护理","鲁迅");
    JsonResult<Book> res=new JsonResult(0,"操作成功啦o(*￣▽￣*)ブ");
    res.setData(book);
    return res;
}
@DeleteMapping(value={"/book/{id}","/book"})
public  JsonResult deleteById(@PathVariable(required = false) String id){
    System.out.println("id:"+id);
    return  new JsonResult(4564665,"电脑C盘已经完成格式化");
}
@PostMapping("/books")
    public JsonResult list(){
    Book java=new Book("112","你有病啊","医生");
    Book mysql=new Book("113","你有药啊","患者");
    List books=new ArrayList();
    books.add(java);
    books.add(mysql);
    JsonResult res=new JsonResult(0,"操作成功啦o(*￣▽￣*)ブ");
    res.setData(books);
    return res;
}
@PostMapping("/book/{name}/{author}")
    public JsonResult save(@PathVariable String name ,@PathVariable String author){
    String content=String.format("name:%s,author:%s",name,author);
    System.out.println(content);
    return new JsonResult(0,"保存成功(ง •_•)ง");

}
}

